package com.wtgroup.demo.mianshi.容器;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author nisus
 * @version 0.1
 * @since 2023/6/8 17:36
 */
public class D_DelayQueue {

    @SneakyThrows
    public static void main(String[] args) {
        DelayQueue queue = new DelayQueue();

        queue.put(new DelayTask(1));

        Delayed take = queue.take();

    }

    @AllArgsConstructor
    static class DelayTask implements Delayed {
        int value;

        @Override
        public long getDelay(TimeUnit unit) {
            return unit.toSeconds(5);
        }

        @Override
        public int compareTo(Delayed o) {
            return this.value - ((DelayTask)o).value;
        }
    }

}
